package com.bcx.crm.java.java8;

import com.bcx.crm.java.java8.Artist;

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Filter {
    public static void main(String[]strings){
        filterTest();
    }
    public static void filterTest(){
        List<Artist> allArtist = new ArrayList<>();
        allArtist.add(new Artist("name1","age1","address1"));
        allArtist.add(new Artist("name2","age2","address2"));
        allArtist.add(new Artist("name3","age3","address3"));
        //根据名字筛选集合
        List<Artist> collect = allArtist.stream().filter(artist -> slave(artist.getName())).collect(Collectors.toList());
        //筛选之后，再用map只能得到第一条，不如直接用map好用，并且当前流会影响下一个流
        Optional<Artist> any = allArtist.stream().filter(artist -> slave(artist.getName()))
                .map(artist -> updateArtistAttribute(artist)).findAny();
        List<Artist> artistList = allArtist.stream().map(artist -> updateArtistAttribute(artist)).collect(Collectors.toList());


    }
    //对名称进行过滤
    private static boolean slave(String name){
        return !"name1".equals(name);
    }
    private static Artist updateArtistAttribute(Artist artist){
        artist.setName(artist.getName()+",");
        return artist;
    }
}
